﻿
//父级对象,高度设自动,祖先固定并overflow:hidden
//向上滚动
var scrollToUp = function (idStr, delay) {
    if (!delay)
        delay = 50
    var o = $("#" + idStr);
    if (o.length <= 0)
        return;
    var op = o.parent();
    var oh = o.height();
    var ph = op.height();
    if (oh > ph) {
        var clObj = o.clone().attr("id", "jq_" + idStr);
        clObj.appendTo(op);
        var jqMarqueeXBottom = function () {
            var boxTop = op.scrollTop();
            if (oh - boxTop <= 0)
                op.scrollTop(boxTop - oh);
            else {
                var ntop = boxTop + 1;
                op.scrollTop(ntop);
            }
        }
        var jqmarqueeFun = window.setInterval(function () { jqMarqueeXBottom(); }, delay);
        op.hover(function () {
            window.clearInterval(jqmarqueeFun);
        }, function () {
            jqmarqueeFun = window.setInterval(function () { jqMarqueeXBottom(); }, delay);
        });
    }
}

//向左滚动
//要复制的ID(itemBox),元素样式名称(Item),祖先固定并overflow:hidden的ID,时间
//scrollToLeft("jqlist","pic-list","randbox");
//<div id="randbox" style="width: 910px; height: 280px; overflow: hidden;"><div style="width: 9999px;"><div id="jqlist"> pic-list
var scrollToLeft = function (cloneID, subClassName, parentBoxID, delay) {
    if (!delay)
        delay = 50
    var o = $("#" + cloneID);
    var pbox = $("#" + parentBoxID);
    if (o.length <= 0 || pbox.length <= 0)
        return;
    var itemArr = o.find("." + subClassName);
    var itemML = parseInt(itemArr.eq(0).css("margin-left"));
    var itemMR = parseInt(itemArr.eq(0).css("margin-right"));
    var itemWidth = itemArr.eq(0).outerWidth(true); //itemArr.eq(0).width() + (!isNaN(itemML) ? itemML : 0) + (!isNaN(itemMR) ? itemMR : 0);
    var ow = itemWidth * itemArr.length;
    var op = o.parent();
    var pw = pbox.width();
    if (ow > pw) {
        o.width(ow);
        var clObj = o.clone().attr("id", "jq_" + cloneID);
        clObj.appendTo(op);

        var jqMarqueeToleft = function () {
            var boxLeft = pbox.scrollLeft();
            if (ow - boxLeft <= 0)
                pbox.scrollLeft(boxLeft - ow);
            else {
                var nleft = boxLeft + 2;
                pbox.scrollLeft(nleft);
            }
        }
        var jqmarqueeTLFun = window.setInterval(function () { jqMarqueeToleft(); }, delay);
        op.hover(function () {
            window.clearInterval(jqmarqueeTLFun);
        }, function () {
            jqmarqueeTLFun = window.setInterval(function () { jqMarqueeToleft(); }, delay);
        });
    }
}


//                <div class="productItemBox" id="pibox">
//                    
//                    <div style="width:99999px;">
//                        <ul class="productlist" id="piul">
//                            <asp:Repeater ID="rep_product" runat="server">
//                                <ItemTemplate>
//                                    <li class="pitem"><a href="<%# Eval("id", "/Product/Show/{0}.html") %>" target="_blank">
//                                        <img src="<%# WebNET.WebClass.SysBase.ImageThumbnaiGet(Eval("productLogo", "{0}"))%>" alt="<%# Eval("Title", "{0}")%>" title="<%# Eval("Title", "{0}")%>" />
//                                    </a></li>
//                                </ItemTemplate>
//                            </asp:Repeater>
//                        </ul>
//                    </div>
//                </div>
//        $(function () {
//            scrollToLeft("piul", "pitem", "pibox");
//        });                
//
///*****产品******/
//.productItemBox{ padding:10px 0; width:820px; height:124px; overflow:hidden; }
//.productlist{ overflow:hidden; height:100%; width:99999px; float:left;}
//.productlist li{ float:left; margin:0 5px 0 6px; width:190px; height:120px; padding:1px; border:1px solid #ccc; overflow:hidden;}
//.productlist li img{ width:190px; height:120px;}

//.Product_li{ padding:10px 5px 10px 5px; float:left;}
//.Product_name{ text-align:center;}


